#ifndef QFUNCTIONTRAITS_H
#define QFUNCTIONTRAITS_H

#include <functional>

// 函数特征提取模板
template<typename T>
struct QFunction_traits;

// 特化：函数指针
template<typename R, typename A1, typename A2>
struct QFunction_traits<R(*)(A1,A2)> {
    using result_type = R;
    using arg1_type = A1;
    using arg2_type = A2;
    static constexpr std::size_t arity = 2;
};

// 特化：std::function
template<typename R, typename A1, typename A2>
struct QFunction_traits<std::function<R(A1,A2)>> {
    using result_type = R;
    using arg1_type = A1;
    using arg2_type = A2;
    static constexpr std::size_t arity = 2;
};

// 特化：lambda/函数对象（通过 operator()）
template<typename T>
struct QFunction_traits : public QFunction_traits<decltype(&T::operator())> {};

// 特化：成员函数指针（非const）
template<typename C, typename R, typename A1, typename A2>
struct QFunction_traits<R(C::*)(A1,A2)> {
    using result_type = R;
    using arg1_type = A1;
    using arg2_type = A2;
    static constexpr std::size_t arity = 2;
};

// 特化：成员函数指针（const）
template<typename C, typename R, typename A1, typename A2>
struct QFunction_traits<R(C::*)(A1,A2) const> {
    using result_type = R;
    using arg1_type = A1;
    using arg2_type = A2;
    static constexpr std::size_t arity = 2;
};

#endif // QFUNCTIONTRAITS_H
